package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Primary
public class DeptServiceImpl2 implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpService empService;


    @Override
    public List<Dept> selectAll() {
        return deptMapper.selectAll();
    }

    //要求删除部门的时候 删除下面的员工
    @Transactional
    @Override
    public int delById(Integer deptid) {
        int i = deptMapper.delById(deptid);
        int i1 = empService.delById(deptid);
        return i;
    }

    @Override
    public int insertDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        return deptMapper.insertDept(dept);
    }


}
